<meta name="content-type" content="text/html; charset=UTF-8" />

<div id="order_detail_div">
	<table id="order_detail_table" class="table table-bordered table-hover table-condensed tb" style="text-align: center;">
		<tr>
			<td>产品名称</td>
			<td>产品类型</td>
			<td>产品价格(元)</td>
		</tr>
	</table>
	
	<input id="pageODNo" type="hidden" value="1">
	<input id="pageODTotalPages" type="hidden" value="0">
	
	<div class="div_page">
		<ul class="pagination">
			<li id="order_detail_headPage"><a href="javascript:void(0)">首页</a></li>
			<li id="order_detail_prePage"><a href="javascript:void(0)">上一页</a></li>
			<li id="order_detail_nextPage"><a href="javascript:void(0)">下一页</a></li>
			<li id="order_detail_tailPage"><a href="javascript:void(0)">尾页</a></li>
			<li>
				<a>
					第<input id="txtODPageNumber" value="${pageODNo}" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" type="text" />
					~&nbsp;共&nbsp;
					<span id="span_totalODPages">${totalODPages}</span>
					&nbsp;页/
					<span id="span_totalODResults">${totalODResults}</span>条
				</a>
			</li>
		</ul>
	</div>
</div>

<script type="text/javascript">
	$(document).ready(function() {
		//点击上一页
		$("#order_detail_prePage").click(function() {
			if ($(this).hasClass("disabled")) return;
			//当前页
			var page = $("#pageODNo").val();
			//总页数
			var pages = $("#pageODTotalPages").val();
			page = page * 1;
			pages = pages * 1;
			page --;
			//确保当前页不会超出范围
			if (page <= 1) page = 1;
			if (page > pages) page = pages;
			if (pages <= 1) {
				$("#order_detail_prePage").addClass("disabled");
				$("#order_detail_nextPage").addClass("disabled");
			} else {
				$("#order_detail_prePage").removeClass("disabled");
				$("#order_detail_nextPage").removeClass("disabled");
				if (page <= 1) {
					$("#order_detail_prePage").addClass("disabled");
				} else {
					$("#order_detail_prePage").removeClass("disabled");
				}
				
				//数据库查询
				var orderId = "";
				var name = $("input[name^='prorder_']:checked").attr("name");
				orderId = name.substring(8, name.length);
				$.ajax({
					type		: "post",
					url 		: "yueyogaAdmin/findOrderDetailByOrderId.jhtml",
					async		: false,
					data		: {"orderId": orderId, "start": page, "limit": 5},
					success		: function(response) {
						var res = eval("(" + response + ")");
						if (res.success) {
							$("#order_detail_table").html("<tr><td>产品名称</td><td>产品类型</td><td>产品价格(元)</td></tr>");
							for (var i = 0;i < res.total;i ++) {
								$("#order_detail_table").append("<tr><td>" + res.items[i].productName + "</td><td>" + res.items[i].productType + "</td><td>" + res.items[i].productPrice + "</td></tr>");
							}
							
							pages = res.totalPages * 1;
							if (pages <= 1) {
								$("#order_detail_prePage").addClass("disabled");
								$("#order_detail_nextPage").addClass("disabled");
							} else {
								if (page <= 1) {
									$("#order_detail_prePage").addClass("disabled");
								} else {
									$("#order_detail_prePage").removeClass("disabled");
								}
							}
							
							//设置当前页
							$("#txtODPageNumber").val(page);
							$("#pageODNo").val(page);
							//设置总页数
							$("#pageODTotalPages").val(pages);
							//显示共几页
							$("#span_totalODPages").text(pages);
							//显示共几条数据
							$("#span_totalODResults").text(res.totalResults);
						} else {
							error(res.msg);
						}
					}
				});
			}
		});
		
		//下一页
		$("#order_detail_nextPage").click(function() {
			if ($(this).hasClass("disabled")) return;
			//当前页
			var page = $("#pageODNo").val();
			//总页数
			var pages = $("#pageODTotalPages").val();
			page = page * 1;
			pages = pages * 1;
			page ++;
			if (page <= 1) page = 1;
			if (page > pages) page = pages;
			if (pages <= 1) {
				$("#order_detail_prePage").addClass("disabled");
				$("#order_detail_nextPage").addClass("disabled");
			} else {
				$("#order_detail_prePage").removeClass("disabled");
				$("#order_detail_nextPage").removeClass("disabled");
				if (page <= 1) {
					$("#order_detail_nextPage").addClass("disabled");
				} else if (page > pages) {
					$("#order_detail_nextPage").addClass("disabled");
				} else {
					$("#order_detail_nextPage").removeClass("disabled");
				}
				
				//数据库查询
				var orderId = "";
				var name = $("input[name^='prorder_']:checked").attr("name");
				orderId = name.substring(8, name.length);
				$.ajax({
					type		: "post",
					url 		: "yueyogaAdmin/findOrderDetailByOrderId.jhtml",
					async		: false,
					data		: {"orderId": orderId, "start": page, "limit": 5},
					success		: function(response) {
						var res = eval("(" + response + ")");
						if (res.success) {
							$("#order_detail_table").html("<tr><td>产品名称</td><td>产品类型</td><td>产品价格(元)</td></tr>");
							for (var i = 0;i < res.total;i ++) {
								$("#order_detail_table").append("<tr><td>" + res.items[i].productName + "</td><td>" + res.items[i].productType + "</td><td>" + res.items[i].productPrice + "</td></tr>");
							}
							
							pages = res.totalPages * 1;
							if (pages <= 1) {
								$("#order_detail_prePage").addClass("disabled");
								$("#order_detail_nextPage").addClass("disabled");
							} else {
								if (page <= 1) {
									$("#order_detail_nextPage").addClass("disabled");
								} else if (page >= pages) {
									$("#order_detail_nextPage").addClass("disabled");
								} else {
									$("#order_detail_nextPage").removeClass("disabled");
								}
							}
							
							//设置当前页
							$("#txtODPageNumber").val(page);
							$("#pageODNo").val(page);
							//设置总页数
							$("#pageODTotalPages").val(pages);
							//显示共几页
							$("#span_totalODPages").text(pages);
							//显示共几条数据
							$("#span_totalODResults").text(res.totalResults);
						} else {
							error(res.msg);
						}
					}
				});
			}
		});
		
		//首页
		$("#order_detail_headPage").click(function() {
			var page = 1;
			var orderId = "";
			var name = $("input[name^='prorder_']:checked").attr("name");
			orderId = name.substring(8, name.length);
			$.ajax({
				type		: "post",
				url 		: "yueyogaAdmin/findOrderDetailByOrderId.jhtml",
				async		: false,
				data		: {"orderId": orderId, "start": page, "limit": 5},
				success		: function(response) {
					var res = eval("(" + response + ")");
					if (res.success) {
						$("#order_detail_table").html("<tr><td>产品名称</td><td>产品类型</td><td>产品价格(元)</td></tr>");
						for (var i = 0;i < res.total;i ++) {
							$("#order_detail_table").append("<tr><td>" + res.items[i].productName + "</td><td>" + res.items[i].productType + "</td><td>" + res.items[i].productPrice + "</td></tr>");
						}
						
						pages = res.totalPages * 1;
						if (pages <= 1) {
							$("#order_detail_prePage").addClass("disabled");
							$("#order_detail_nextPage").addClass("disabled");
						} else {
							$("#order_detail_prePage").addClass("disabled");
							$("#order_detail_nextPage").removeClass("disabled");
						}
						
						//设置当前页
						$("#txtODPageNumber").val(page);
						$("#pageODNo").val(page);
						//设置总页数
						$("#pageODTotalPages").val(pages);
						//显示共几页
						$("#span_totalODPages").text(pages);
						//显示共几条数据
						$("#span_totalODResults").text(res.totalResults);
					} else {
						error(res.msg);
					}
				}
			});
		});
		
		//尾页
		$("#order_detail_tailPage").click(function() {
			var page = $("#pageODTotalPages").val();
			page = page * 1;
			var orderId = "";
			var name = $("input[name^='prorder_']:checked").attr("name");
			orderId = name.substring(8, name.length);
			$.ajax({
				type		: "post",
				url 		: "yueyogaAdmin/findOrderDetailByOrderId.jhtml",
				async		: false,
				data		: {"orderId": orderId, "start": page, "limit": 5},
				success		: function(response) {
					var res = eval("(" + response + ")");
					if (res.success) {
						$("#order_detail_table").html("<tr><td>产品名称</td><td>产品类型</td><td>产品价格(元)</td></tr>");
						for (var i = 0;i < res.total;i ++) {
							$("#order_detail_table").append("<tr><td>" + res.items[i].productName + "</td><td>" + res.items[i].productType + "</td><td>" + res.items[i].productPrice + "</td></tr>");
						}
						
						pages = res.totalPages * 1;
						if (pages <= 1) {
							$("#order_detail_prePage").addClass("disabled");
							$("#order_detail_nextPage").addClass("disabled");
						} else {
							$("#order_detail_prePage").removeClass("disabled");
							$("#order_detail_nextPage").removeClass("disabled");
							if (page <= 1) {
								$("#order_detail_nextPage").addClass("disabled");
							} else if (page >= pages) {
								$("#order_detail_nextPage").addClass("disabled");
							} else {
								$("#order_detail_nextPage").removeClass("disabled");
							}
						}
						
						//设置当前页
						$("#txtODPageNumber").val(page);
						$("#pageODNo").val(page);
						//设置总页数
						$("#pageODTotalPages").val(pages);
						//显示共几页
						$("#span_totalODPages").text(pages);
						//显示共几条数据
						$("#span_totalODResults").text(res.totalResults);
					} else {
						error(res.msg);
					}
				}
			});
		});
		
		//输入页数
		$("#txtODPageNumber").keyup(function() {
			var page = $(this).val();
			var pages = $("#pageODTotalPages").val();
			page = page * 1;
			pages = pages * 1;
			
			if (page < 1) page = 1;
			if (page > pages) page = pages;
			
			var orderId = "";
			var name = $("input[name^='prorder_']:checked").attr("name");
			orderId = name.substring(8, name.length);
			$.ajax({
				type		: "post",
				url 		: "yueyogaAdmin/findOrderDetailByOrderId.jhtml",
				async		: false,
				data		: {"orderId": orderId, "start": page, "limit": 5},
				success		: function(response) {
					var res = eval("(" + response + ")");
					if (res.success) {
						$("#order_detail_table").html("<tr><td>产品名称</td><td>产品类型</td><td>产品价格(元)</td></tr>");
						for (var i = 0;i < res.total;i ++) {
							$("#order_detail_table").append("<tr><td>" + res.items[i].productName + "</td><td>" + res.items[i].productType + "</td><td>" + res.items[i].productPrice + "</td></tr>");
						}
						
						pages = res.totalPages * 1;
						if (pages <= 1) {
							$("#order_detail_prePage").addClass("disabled");
							$("#order_detail_nextPage").addClass("disabled");
						} else {
							$("#order_detail_prePage").removeClass("disabled");
							$("#order_detail_nextPage").removeClass("disabled");
							if (page <= 1) {
								$("#order_detail_prePage").addClass("disabled");
								$("#order_detail_nextPage").removeClass("disabled");
							} else if (page >= pages) {
								$("#order_detail_prePage").removeClass("disabled");
								$("#order_detail_nextPage").addClass("disabled");
							} else {
								$("#order_detail_prePage").removeClass("disabled");
								$("#order_detail_nextPage").removeClass("disabled");
							}
						}
						
						//设置当前页
						$("#txtODPageNumber").val(page);
						$("#pageODNo").val(page);
						//设置总页数
						$("#pageODTotalPages").val(pages);
						//显示共几页
						$("#span_totalODPages").text(pages);
						//显示共几条数据
						$("#span_totalODResults").text(res.totalResults);
						console.log(page);
					} else {
						error(res.msg);
					}
				}
			});
		});
		
	});
</script>
